﻿using Newtonsoft.Json;

namespace WebApi.Models.Common
{
    /// <summary>
    /// 响应实体
    /// </summary>
    public class ResultInfoModel
    {
        /// <summary>
        /// 信息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 返回数据
        /// </summary>
        public dynamic ReturnData { get; set; } = string.Empty;
    }

    /// <summary>
    /// 获取结果
    /// </summary>
    public class GetResult
    {
        /// <summary>
        /// 返回错误
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ResultInfoModel Error(string msg)
        {
            return new ResultInfoModel
            {
                Message = msg,
                IsSuccess = false
            };
        }

        /// <summary>
        /// 返回错误（带数据）
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ResultInfoModel Error<T>(string msg, T data)
        {
            return new ResultInfoModel
            {
                Message = msg,
                IsSuccess = false,
                ReturnData = data
            };
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ResultInfoModel Success(string msg)
        {
            return new ResultInfoModel
            {
                Message = msg,
                IsSuccess = true
            };
        }

        public static ResultInfoModel Success<T>(string msg, T data)
        {
            return new ResultInfoModel
            {
                Message = msg,
                IsSuccess = true,
                ReturnData = data
            };
        }

        public static ResultInfoModel Success(string msg, dynamic data)
        {
            return new ResultInfoModel
            {
                Message = msg,
                IsSuccess = true,
                ReturnData = data
            };
        }
    }

}